package com.problem.leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

/**
 * @author didi
 * @DESCRIPTION problem387
 * @create 2018-04-23 上午10:56
 **/

public class Problem387 {
    public int firstUniqChar(String s) {
        if (s == null || s.length() <= 0) {
            return -1;
        }

        if (s.length() == 1) {
            return 0;
        }

        char[]  strs = s.toCharArray();
        int[] ascii = new int[256];
        for (int index = 0; index < strs.length; ++index) {
            ascii[strs[index]]++;
        }

        for (int index = 0; index < strs.length; ++index) {
            if(ascii[strs[index]] == 1) {
                return index;
            }
        }
        return -1;

    }

    public static void main(String[] args) {
        Problem387 problem387 = new Problem387();
        int        result     = problem387.firstUniqChar("leetcode");
        System.out.println(result);
    }

}
